import {ToolRoute} from '../utils';
let _formateRoutes = []
const routes = [
  {
    label: '目录',
    path: '/list',
    view: 'pages/Home' //一级路由组件：相对于src目录
  },
  {label: '登录', path: '/login', view: 'pages/login'},
  {
    label: '表单', //二级路由的标题，同时是一级底部标签栏的标题
    path: '/form', //二级路由的地址，不以'/'开头，同时是一级底部标签栏的Key
    icon: 'wode', //一级底部标签栏的图标类型
    view: 'components/form/Demo', //二级路由组件：相对于src目录
    // auths: [1, 2], //权限列表：1是管理员，2是开发，3是测试，4是产品。如果未定义auths，则表示不需要校验权限。
    children: [
      {
        label: '表单2', //二级路由的标题，同时是二级底部标签栏的标题
        path: '/form2', //二级路由的地址，不以'/'开头，同时是二级底部标签栏的标题
        view: 'components/form/Demo', //二级路由组件：相对于src目录
        // auths: [1, 2]
      }
    ]
  },
  {label: '图标', path: '/icon', icon: 'wode', view: 'components/icon/Demo', Demo: [1, 2]},
  {label: '国际化', path: '/locale', icon: 'wode', view: 'components/locale/Demo', Demo: [1, 2]},
  {label: '订单', path: '/order', icon: 'wodeguanzhu', view: 'pages/order'}
]

function formateRoutes(routes, parentPath = '') {
  routes.forEach(item => {
    const { path, view, exact, children, ...others } = item
    const MERGE_PATH = parentPath + path
    if(children && Array.isArray(children) && children.length) {
      formateRoutes(children, MERGE_PATH)
      return
    }
    const URL = MERGE_PATH.startsWith('/')? MERGE_PATH : ('/'+ MERGE_PATH)
    _formateRoutes.push(ToolRoute.route(URL, view, exact, others))
  })
}

formateRoutes(routes)

export default _formateRoutes